﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MvcMall.Core.Contacts.Tasks;
using MvcMall.Core.Domains;
using MvcMall.Framework.MvcPager;

namespace MvcMall.AdminWeb.Manage.GoodsCategories
{
    public partial class Details : ManageBasePage
    {
        private IGoodsCategoryTask _goodsCategoryTask;
        protected void Page_Load(object sender, EventArgs e)
        {
            ValidatePagePower("GoodsCategoriesIndex");

            _goodsCategoryTask = GetInstance<IGoodsCategoryTask>();

            if (!IsPostBack)
            {
                var id = 0;
                if (Request.QueryString["Id"] != null && Int32.TryParse(Request.QueryString["Id"], out id))
                {
                    var info = _goodsCategoryTask.Get(id);
                    if (info == null)
                    {
                        ShowMsg("参数错误", "/Manage/Index.aspx");
                    }

                    BindInfo(info);
                }
                else
                {
                    ShowMsg("参数错误", "/Manage/Index.aspx");
                }
            }
        }

        private void BindInfo(GoodsCategory info)
        {
            lblSortOrder.Text = info.SortOrder.ToString();
            lblParentCatName.Text = info.ParentCat.CatName;
            lblKeyWords.Text = info.Keywords;
            lblId.Text = info.Id.ToString();
            lblGoodsNumber.Text = info.GoodsNumber.ToString();
            lblCatName.Text = info.CatName;
            lblCatGrade.Text = info.CatGrade.ToString();
            lblCatDesc.Text = info.CatDesc;

            rptAttributes.DataSource = info.GoodsCategoryAttributes;
            rptAttributes.DataBind();

            rptChildCats.DataSource = info.ChildCats;
            rptChildCats.DataBind();
        }


    }
}